package sk.hackcraft.util.agent_simulation.agent;

import sk.hackcraft.util.agent_simulation.AgentSimulation;
import sk.hackcraft.util.agent_simulation.AgentSimulationComponent;
import sk.hackcraft.util.agent_simulation.messaging.Message;
import sk.hackcraft.util.agent_simulation.messaging.MessageProcessor;
import sk.hackcraft.util.agent_simulation.messaging.MessageType;

public abstract class ContinualAssistant extends AgentSimulationComponent implements MessageProcessor
{
	private final Agent agent;
	
	public ContinualAssistant(AgentSimulation agentSimulation, Agent agent)
	{
		super(agentSimulation);
		this.agent = agent;
	}
	
	protected Agent getAgent()
	{
		return agent;
	}
	
	public void hold(Message message)
	{
		message.setMessageType(MessageType.HOLD);
		message.setAddressee(this);
		getAgentSimulation().sendMessage(message);
	}
	
	public void notice(Message message)
	{
		message.setMessageType(MessageType.NOTICE);
		message.setDeliveryTime(getAgentSimulation().getCurrentTime());
		getAgentSimulation().sendMessage(message);
	}
	
	public void finish(Message message)
	{
		message.setMessageType(MessageType.FINISH);
		message.setDeliveryTime(getAgentSimulation().getCurrentTime());
		message.setAddressee(agent.getManager());
		getAgentSimulation().sendMessage(message);
	}

	@Override
	public void processMessage(Message message)
	{
		processMessageAction(message);
	}
	
	protected abstract void processMessageAction(Message message);
}
